// import axios from 'axios';

const registerUser = async (params) => {
    let formData = new FormData();
    formData.append('username', params.username);
    formData.append('password', params.password);
    formData.append('name', params.name);
    formData.append('mobile', params.mobile);
    formData.append('code', params.code);
    formData.append('openid', params.openid || undefined);
    formData.append('UnionId', params.UnionId);
    return await new Promise((resolve, reject) => {
        axios.post('/sys/register/registerUser', formData).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

const resetPassword = async (params) => {
    let formData = new FormData();
    formData.append('code', params.code);
    formData.append('password', params.password);
    return new Promise((resolve, reject) => {
        axios.post('/sys/login/updatePasswordByMobile', formData).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

const malaySiaRegister = async (params) => {
    let formData = new FormData();
    formData.append('username', params.user_name);
    formData.append('password', params.password);
    formData.append('UnionID', params.UnionID);
    formData.append('name', params.name);
    formData.append('mobile', params.mobile);
    return new Promise((resolve, reject) => {
        axios.post('/sys/register/linkNewSysByUserName', formData).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

export default {
    registerUser,
    resetPassword,
    malaySiaRegister
}
